<template>
  <div class="app-container">
    <!-- banner列表 -->
    <el-table :data="list" stripe style="width: 100%">
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="userAddress" label="用户链上地址" />
      <el-table-column prop="userName" label="用户名" />
      <el-table-column prop="balance" label="用户账户余额" />
      <el-table-column prop="userAssetList" label="用户名下涉及资产集合" />
      <el-table-column prop="createTime" label="用户创建时间" />
    </el-table>
  </div>
</template>

<script>
import user from '@/api/user'

export default {
  data() {
    return {
      list: []
    }
  },
  created() {
    this.findAllUser()
  },
  methods: {
    findAllUser() {
      user
        .findAllUser()
        .then((response) => {
          const temp = response.data
          for (let i = 0; i < temp.length; i++) {
            temp[i].createTime = this.timeFormatConversion(temp[i].createTime)
            temp[i].userAssetList = this.arrayToString(temp[i].userAssetList)
          }
          this.list = temp
          console.log(this.list)
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 将数组变成按照一定格式分隔的string
    arrayToString(array) {
      let res = ''
      for (let index = 0; index < array.length; index++) {
        res += array[index] + '\n'
      }
      console.log(res)
      return res
    },
    // 因为你时间传过来的是一个string，这里格式转换就是对字符串操作，如果你后端传过来格式是yyyy-mm-dd HH:MM:ss格式的就不用转换了
    timeFormatConversion(date) {
      return date.slice(0, 10) + ' ' + date.slice(11, 19)
    }
  }
}
</script>
